<template>
  <el-container>
    <el-aside width="226px">
      <!-- logo -->
      <div class="logo"></div>
      <!-- 导航菜单 -->
      <NavBar />
    </el-aside>
    <el-container>
      <el-header>

        <el-dropdown>
          <span class="el-dropdown-link">
            {{ adminInfo.username
            }}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>
              <div @click="logout">安全退出</div>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <el-main>
        <!-- 二级路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
// 导入导航菜单组件
import NavBar from "../components/NavBar.vue";
// 导入工具函数
import { getAdminInfo } from "../utils/common";
export default {
  components: { NavBar },
  data() {
    return {
      // 当前登录账号的信息
      adminInfo: {},
    };
  },
  created() {
    this.adminInfo = getAdminInfo();
  },
  methods: {
    logout() {
      // 1-移除本地存储中的登录信息
      localStorage.removeItem("adminInfo");
      // 2-成功提示
      this.$message.success("退出成功");
      // 3-自动跳转到的登录页面
      this.$router.push({ name: "login" });
    },
  },
};
</script>
<style scoped>
.el-container {
  height: 100vh;
}
.logo {
  height: 60px;
  margin: 0 10px;
  background: url("../assets/imgs/logo-white.png") no-repeat center center;
  background-size: 70%;
}

.el-header {
  background-color: #fff;
  color: #333;
  line-height: 60px;
}
.el-aside {
  background-color: #ff674b;
  color: #fff;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}
.el-dropdown {
  position: absolute;
  right: 10px;
  top: 0;
}
</style>
